// Utilities
import { defineConfig, mergeConfig } from "vite";
import baseConfig from "./vite.config.mjs";
import removeConsole from "vite-plugin-remove-console";
import VitePluginCdnImport from "vite-plugin-cdn-import";
// https://vitejs.dev/config/
export default defineConfig(() => {
  return mergeConfig(baseConfig, {
    // base: "https://project-star.oss-cn-beijing.aliyuncs.com/npm/static/dist/",
    base: "/",
    plugins: [
      removeConsole({
        external: ["src/utils/joinImage.ts"],
      }),
      VitePluginCdnImport({
        modules: [
          {
            name: "vue",
            var: "Vue",
            path: "https://oss.top237.top/npm/vue/@3.5.13/vue.global.prod.js",
          },
          {
            name: "vue-router",
            var: "VueRouter",
            path: "https://oss.top237.top/npm/vue-router/@4.1.0/vue-router.global.prod.js",
          },
          {
            name: "vuex",
            var: "Vuex",
            path: "https://oss.top237.top/npm/vuex/@4.1.0/vuex.global.prod.js",
          },
        ],
      }),
    ],
    define: {
      "process.env": {
        __APP_ENV__: "prod",
      },
    },
    build: {
      target: "es2015",
      rollupOptions: {
        external: ["vue", "vue-router", "vuex"],
        output: {
          manualChunks: {
            "@vueuse/core": ["@vueuse/core"],
            vuetify: ["vuetify"],
            "leafer-ui": ["leafer-ui", "@leafer-in/editor", "@leafer-in/arrow"],
          },
          globals: {
            vue: "Vue",
            "vue-router": "VueRouter",
            vuex: "Vuex",
          },
        },
      },
    },
  });
});
